//This is the main application class.  It extends the Application main class.

#ifndef _MESH_EXAMPLE_H_
#define _MESH_EXAMPLE_H_

#include "../Helix/View/OpenGL/OpenGLSupport.h"
#include "../Helix/Application.h"
#include "../Helix/Window.h"
#include "../Helix/Renderer.h"
#include "../Helix/Updater.h"
#include "../Helix/Input.h"
#include "../Helix/Domain/HelixImage.h"
#include "../Helix/Domain/HelixMesh.h"
#include "../Helix/View/Texture.h"
#include "../Helix/View/OpenGL/OpenGLTexture2D.h"
#include "../Helix/View/RenderHelper.h"

using namespace helix;

//Implements HRenderer and HUpdater
class InputExample : public Renderer, public Updater
{
private:
	float rotX;
	float rotY;
	float zoom;

	Mesh *cube;
    
	OpenGLTexture2D *cubeTexture;

	RenderHelper *openGLHelper;

	Input *input;

public:

	InputExample()
	{
		
	}

	~InputExample()
	{
		delete cubeTexture;
		MeshUtil::deleteMesh(cube);
		//Do not delete openGLHelper because it will be deleted by the application when the app is shut down
	}

	virtual void renderScene();
	virtual void update(double dSeconds);

	void initialize()
	{
		TextureParameters tParams = TextureParameters(TextureParameters::TEXTURE_2D);
		tParams.setMinFilter(TextureParameters::TRILINEAR_SAMPLE_FILTERING);
		tParams.setMaxFilter(TextureParameters::POINT_SAMPLE_FILTERING);
		tParams.setMipMapType(TextureParameters::AUTO_GENERATE_MIP_MAPS);
		tParams.setURepeat(TextureParameters::REPEAT);
		tParams.setVRepeat(TextureParameters::REPEAT);

		//Load the texture
		Image *image= ImageFactory::loadImage("Data/Textures/cube_side.png");
		cubeTexture = new OpenGLTexture2D(image,&tParams);
		ImageFactory::deleteImage(image);

		input = Application::getInstance()->input();

		rotX = 0.0;
		rotY = 0.0;

		zoom = -5.0;

		cube = MeshUtil::loadFromHMF("Data/Meshes/cube-24-verts.hmf");

		openGLHelper = Application::getInstance()->window()->getRenderHelper();

		//Set up our one-time opengl stuff
		glEnable(GL_DEPTH_TEST);			//Enable depth testing (faces hidden behind others will not be drawn)
		glClearColor(0.0,0.0,0.0,1.0);		//Set the clear color (color of the background)
		glEnable(GL_TEXTURE_2D);			//Enable texturing
		glBindTexture(GL_TEXTURE_2D,cubeTexture->getId());	//Set our texture as the currently bound one
	}
};

#endif
